<?php
/**
* File that sets view of edit colors page.
* @package busmap
*/
?>
<?php if(count($this->entries)){ ?>
	<h3>Värvid</h3>
	<table class="data-listing" cellspacing=0 cellpadding=0 border=0>
		<tr>
			<th>Värvi nimi</th>
			<th>Punane | Roheline | Sinine</th>
			<th>Värv</th>
			<th class="button">Tegevused</th>
		</tr>
		<tr>
			<td colspan="4">
			    <?php foreach ($this->entries as $entry){
				if(array_key_exists('id', $_POST) && $_POST['id'] == $entry->id){
					
					if(count($this->changeColorFormErrors)){
						$errorsTxt = '';
						foreach($this->changeColorFormErrors as $error){
							$errorsTxt .= '<div class="withErrors">'.array_pop($error).'</div>';
						}
						echo $errorsTxt;
					}
					if(array_key_exists('delete', $_POST)){
						$this->changeColorForm = new Application_Form_Admin_editColor();
						$this->changeColorForm->populate($entry->toArray());
						$this->changeColorForm->askDeleteConfirmation();
					}
					$this->changeColorForm->setColorField($entry->redValue, $entry->greenValue, $entry->blueValue);
					$colorsForm = $this->changeColorForm;
				}else{
					$colorsForm = new Application_Form_Admin_editColor();
					$colorsForm->populate($entry->toArray());
					$colorsForm->setColorField($entry->redValue, $entry->greenValue, $entry->blueValue);
				}
				echo $colorsForm.'<div style="clear:both;"></div>';
			    }
			    ?>
			</td>
		</tr>
	</table>
<?php }else{ ?>
	Hetkel värvid puuduvad andmebaasis.
<?php } ?>
<h4>Lisa uus värv</h4>
<?php
if(count($this->errors)){
	$errorsTxt = '';
	foreach($this->errors as $error){
		$errorsTxt .= '<div class="withErrors">'.array_pop($error).'</div>';
	}
	echo ($errorsTxt)?$errorsTxt:'';
}
?>
<table class="data-listing">
	<tr>
		<th>Värvi nimi</th>
		<th>Punane | Roheline | Sinine</th>
		<th class="button">Lisa</th>
	</tr>
	<tr>
		<td colspan="3">
			<?php
				echo $this->insertColorForm;
			?>
		</td>
	</tr>
</table>